#!/usr/bin/env php
<?php

if (file_exists(__DIR__ . '/../../autoload.php')) {
    require __DIR__ . '/../../autoload.php';
} else {
    require __DIR__ . '/vendor/autoload.php';
}

if (!empty($argv[1])) {
    $waitFiles = [$argv[1]];
} else {
    $waitFiles = scandir('./');
}

if (strtolower(PHP_OS) == 'winnt') {
    $pwd = exec("chdir");
} else {
    $pwd = exec("pwd");
}

echo date('H:i:s') . " php format start...\n";

try {
    $fmt = new \Jackdou\PhpFmt\PhpFmt(new \Jackdou\PhpFmt\PhpFile($waitFiles, $pwd), new \Jackdou\PhpFmt\PhpCache());

    $fmt->run();
} catch (Throwable $exception) {
    echo "oops,php format error,message:\n";
    echo $exception->getMessage() . "\n";
}

echo date('H:i:s') . " php format end...\n";
